package cn.gson.springboot.controller;

import cn.gson.springboot.model.pojos.Employee;
import cn.gson.springboot.model.pojos.Function;
import cn.gson.springboot.model.pojos.FunctionType;
import cn.gson.springboot.model.service.FunctionService;
import cn.gson.springboot.model.service.FunctionTypeService;
import com.alibaba.fastjson.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
public class FunctionController {
    @Autowired
    FunctionService fs;
    @Autowired
    HttpSession session;

    @RequestMapping("/job-funs")
    @ResponseBody
    public  Map<String,Object> empFuns(Integer jobId){
        Map<String,Object> map = new HashMap<>();
        List<Function> functions = fs.allFuns(jobId);
        List<Integer> jobFuns = fs.jobFuns(jobId);
        map.put("functions",functions);
        map.put("jobFuns",jobFuns);
        return map;
    }

    @RequestMapping("/save-job-jurisdiction")
    @ResponseBody
    public void saveJobJurisdiction(@RequestParam("str") String str){
        JSONObject parse = (JSONObject)JSONObject.parse(str);
        Integer jobId = (Integer) parse.get("jobId");
        List<Integer> funId = (List<Integer>)parse.get("funId");
        fs.saveJobJurisdiction(jobId,funId);

    }
    @RequestMapping("/funtype-funs")
    @ResponseBody
    public List<Function> funs(Integer funTypeId){
        return fs.funs(funTypeId);
    }
    
    @RequestMapping("/funtype-funs-vague")
    @ResponseBody
    public List<Function> funVague(String content){
        return fs.funVague(content);
    }
}
